import React, { useEffect, useState } from 'react';
import { message } from "antd";
import { useNavigate } from 'react-router-dom';
function useAuth() {
    const navigate=useNavigate()
    const [isAuth,setIsAuth]=useState(()=>{
        const token=localStorage.getItem('token')
        return !!token
    })
    useEffect(()=>{
        const token=localStorage.getItem('token')
        if(!token){
            setIsAuth(false)
            message.error('请先登录')
            setTimeout(()=>{
                navigate('/login')
            },1000)
        }
    },[navigate])
    return isAuth;
}

export default useAuth;